#!/usr/bin/env perl

use utf8;
use strict;
no warnings 'experimental::smartmatch';
use 5.010001;

say "Checking the number <$ARGV[0]>";

given($ARGV[0]){
	when (!/\A\d+\Z/){
		say "Not a number ..";
	}
	my @divisors = divisors($_);

	my @empty;
	when (@divisors ~~ @empty){
		say "Number is a prime";
	}
	default{
		say "$_ is divisible by @divisors";
	}
}

sub divisors{
	my $number = shift;

	my @divisors = ();

	foreach my $divisor (2 .. $number / 2){
		push @divisors, $divisor unless $number % $divisor;
	}

	@divisors;
}